package asteroids.expression;

import asteroids.model.programs.*;

public class NumericExpression extends Expression{
	double value;
	Expression arg1;
	Expression arg2;
	private Expression initialArg1;
	private Expression initialArg2;
	
	public NumericExpression(Expression exp1, Expression exp2){
		if( ( (exp1 instanceof Variable)||(exp1 instanceof NumericExpression)||(exp1 instanceof EntityExpression) )&&( (exp2 instanceof Variable)||(exp2 instanceof NumericExpression)||(exp2 instanceof EntityExpression) ) ){
			initialArg1 = exp1;
			initialArg2 =exp2;
		}else{
			initialArg1 = new NumericExpression();
			initialArg2 = new NumericExpression();
		}
	}
	public NumericExpression(Expression exp1){
		if(exp1 instanceof NumericExpression||exp1 instanceof EntityExpression||exp1 instanceof Variable){
			initialArg1 = exp1;
		}
	}
	public NumericExpression(){
		this.value=0.001;
	}
	
	public void setValue(double newValue){
		this.value = newValue;
	}
	public double getValue(Program program){
		return this.value;
	}
	public void updateArguments(Program program) {
		Expression tempArg1 = initialArg1;
		Expression tempArg2 = initialArg2;
		if(this.initialArg1 instanceof Variable){
			tempArg1= ((Variable)initialArg1).getRef(program);
		}
		if(this.initialArg2 instanceof Variable){
			tempArg2= ((Variable)initialArg2).getRef(program);
		}
		if(!((tempArg1 instanceof EntityExpression)||(tempArg1 instanceof NumericExpression)) ){
			tempArg1 = new NumericExpression();
		}
		if(!((tempArg2 instanceof EntityExpression)||(tempArg2 instanceof NumericExpression)) ){
			tempArg2 = new NumericExpression();
		}
		this.arg1=tempArg1;
		this.arg2=tempArg2;

	}
	
	
	
	
	@Override
	public String toString(Program program) {
		Double d = this.getValue(program);
		String s = Double.toString(d);
		return "" + s;
	}

}
